package com.nxj.spring_web_sz.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.LocaleResolver;
import org.springframework.web.servlet.View;
import org.springframework.web.servlet.ViewResolver;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.Locale;

/**
 * @author 77317
 * @Title: myConfig
 * @projectName spring_web_sz
 * @description: 拓展springmvc
 *
 *
 * Ctrl+o进入
 * @date 2020/5/13 14:13
 * @Version V1.0
 */
@Configuration
public class MyConfig implements WebMvcConfigurer {
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new LoginHandlerInterceptor()).
                addPathPatterns("/**").excludePathPatterns("/index.html","/"
                ,"/user/login","/css/**","/js/**","/img/**");
    }

    @Override
    public void addViewControllers(ViewControllerRegistry registry) {

        registry.addViewController("/").setViewName("index");
        registry.addViewController("/index.html").setViewName("index");
        registry.addViewController("/main.html").setViewName("dashboard");
    }
    //自定义国际化组件生效
    @Bean
    public LocaleResolver localeResolver(){
        return  new MyLocaleResolver();
    }
//    @Bean
//    public  ViewResolver myViewResolver(){
//        return  new MyViewResolver();
//    }
//    //自定义视图解析器
//    public  static  class MyViewResolver implements ViewResolver{
//
//        @Override
//        public View resolveViewName(String viewName, Locale locale) throws Exception {
//
//            return null;
//        }
//    }
}
